
package efg1;
import efg.List;
import efg.stacklist;
import java.util.Scanner;
public class test2 {
    public static void main(String[] args){
      List a=new stacklist(); 
      String s;
      int n=0;
      char m[]=new char[100];
      Scanner reader=new Scanner(System.in);
      System.out.println("请输入随意一个带括号的数学表达式(包含（）,[],{})：");
      s=reader.next();
      System.out.println("这些字符串是："+s);
      for(int i=0;i<s.length();i++){
          if(s.charAt(i)=='('||s.charAt(i)==')'||s.charAt(i)=='{'||s.charAt(i)=='}'||s.charAt(i)=='['||s.charAt(i)==']'){
              m[n]=s.charAt(i);
              n++;
          }
      }
     for(int i=0;i<n;i++){
         Object o;
         if(m[0]==']'||m[0]==')'||m[0]=='}')
             throw new ArrayIndexOutOfBoundsException("该表达式不匹配");
         if(m[i]=='('||m[i]=='{'||m[i]=='[')
             a.push(m[i]);
         if(m[i]==')'){
             if(a.isEmpty()==false&&(char)a.getTop()=='(')
                  o=a.pop();
             else  
               throw new ArrayIndexOutOfBoundsException("该表达式不匹配");
         }
          if(m[i]==']'){
             if(a.isEmpty()==false&&(char)a.getTop()=='[')
                o=a.pop();
             else  
               throw new ArrayIndexOutOfBoundsException("该表达式不匹配");
         }
          if(m[i]=='}'){
             if(a.isEmpty()==false&&(char)a.getTop()=='{')
                o=a.pop();
             else  
               throw new ArrayIndexOutOfBoundsException("该表达式不匹配");
         }  
     }  
         if(a.isEmpty()==true)
             System.out.println("该数学表达式括号匹配");
         else 
             System.out.println("该数学表达式括号不匹配");
          
          }
   
   
}
